﻿@using Webdiyer.WebControls.Mvc;
@model PagedList<hsgsSHXX.Model.PrvUser>
@using MvcContrib.UI.Grid;
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>UserList</title>
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery-ui.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/jquery-ui.custom.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/checkinput.js", true)" type="text/javascript"></script>

    @if (false)
    {
        <script src="../../../../Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript"></script>
    }

    <script type="text/javascript">
        $(document).ready(function () {
            var parOrgNo = $("#parOrgNo").val();
            if (parOrgNo == null || parOrgNo == "") {
                $("#btnResetPwdByOrgan").css("display", "none");
            }
            $("#btnAdd,#btnDeleteUserList,#btnResetPwd,#btnResetPwdByOrgan").button();
            $('#chkHeader').change(function () {
                if ($(this).is(':checked')) {
                    $('.foo').attr('checked', 'checked');
                }
                else {
                    $('.foo').removeAttr('checked');
                }
            });
            $("#btnAdd").bind("click", function () {
                add();
            });
            $("#btnDeleteUserList").bind("click", function () {
                DeleteUserList();
            });
            $("#btnResetPwd").bind("click", function () {
                ResetPwd();
            });
            $("#btnResetPwdByOrgan").bind("click", function () {
                ResetPwdByOrgan();
            });

        });
        /*用户增加*/
        function add() {
            var hdOrgNo = $("#hdOrgNo").val();
            window.location.href = "/User/AddUser?orgNo=" + hdOrgNo;
        }
        /*删除用户*/
        function DeleteUser(loginID_En, loginName) {
            if (confirm("确定删除【" + loginName + "】吗？")) {
                $.ajax({
                    type: "POST",
                    url: "/User/DeleteUser",
                    data: { loginID_En: loginID_En },
                    async: true,
                    success: function (jsonstr) {
                        var msg = jsonstr.split('|');
                        if (msg[0] == "SUCCESS") {
                            alert("删除成功");
                            var hdOrgNo = $("#hdOrgNo").val();
                            window.location.href = "UserList?orgNo=" + hdOrgNo + "&FEmp_Status=" + $("#hdFEmp_Status").val();
                        }
                        else {
                            if (msg.length > 1) {
                                alert(msg[1]);
                            }
                        }
                    }
                });
            }
        }
        /*批量删除用户*/
        function DeleteUserList() {
            var str = "";
            $("[name='mycheckbox'][checked]").each(function () {
                str += $(this).val() + ",";
            });
            if (str != "") {
                if (confirm("确定删除所选人员吗？")) {
                    $.ajax({
                        type: "POST",
                        url: "/User/DeleteUserList",
                        data: { loginIDs: str },
                        async: true,
                        success: function (jsonstr) {
                            var msg = jsonstr.split('|');
                            if (msg[0] == "SUCCESS") {
                                alert("删除成功");
                                var hdOrgNo = $("#hdOrgNo").val();
                                window.location.href = "UserList?orgNo=" + hdOrgNo + "&FEmp_Status=" + $("#hdFEmp_Status").val();
                            }
                            else {
                                if (msg.length > 1) {
                                    alert(msg[1]);
                                }
                            }
                        }
                    });
                }
            }
            else {
                alert("请选择人员");
            }
        }
        /*部门密码重置*/
        function ResetPwdByOrgan() {
            var hdOrgNo = $("#hdOrgNo").val();
            var hdorgName = $("#hdorgName").val();
            if (hdOrgNo != "") {
                if (confirm("确定将【" + hdorgName + "】的密码重置为【123456】吗？")) {
                    $.ajax({
                        type: "POST",
                        url: "/User/ResetPwdByOrgan",
                        data: { organizeNo: hdOrgNo },
                        async: true,
                        success: function (jsonstr) {
                            var msg = jsonstr.split('|');
                            if (msg[0] == "SUCCESS") {
                                alert("成功将【" + hdorgName + "】的密码重置为【123456】！");
                            }
                            else {
                                if (msg.length > 1) {
                                    alert(msg[1]);
                                }
                            }
                        }
                    });
                }
            }
        }
        /*密码重置*/
        function ResetPwd() {
            var str = "";
            $("[name='mycheckbox'][checked]").each(function () {
                str += $(this).val() + ",";
            });
            if (str != "") {
                if (confirm("确定重置所选人员的密码为【123456】吗？")) {
                    $.ajax({
                        type: "POST",
                        url: "/User/ResetPwd",
                        data: { loginIDs: str },
                        async: true,
                        success: function (jsonstr) {
                            var msg = jsonstr.split('|');
                            if (msg[0] == "SUCCESS") {
                                alert("密码重置成功为123456");
                            }
                            else {
                                if (msg.length > 1) {
                                    alert(msg[1]);
                                }
                            }
                        }
                    });
                }
            }
            else {
                alert("请选择人员");
            }
        }
    </script>

</head>
<body>
    <div style="padding: 0px; background: #efefef; width: 583px;">
     
        <input type="button" id="btnAdd" value="增加" />&nbsp;
        <input type="button" id="btnDeleteUserList" value="批量删除" style="color: Red" />&nbsp;
       <input type="button" id="btnResetPwd" value="密码重置" />&nbsp;
       <input type="button" id="btnResetPwdByOrgan" value="部门密码重置" style="color: Red" />
       <span>&nbsp;&nbsp;</span>
        @*<a href="/Index/Index">社会信息查询</a>*@
        
    </div>
    <div>
        @Html.Grid(Model).Columns(column =>
   {
       column.For(x => Html.CheckBox("mycheckbox", new { @class = "foo", @value = x.FLogID_En })).Header(x => Html.CheckBox("chkHeader"));

       column.For(x => x.FLogID == "admin" ?
               string.Format(@"<a   href='/User/EditUser?loginID={0}'>编辑</a> | <a href='#' disabled='disabled'>删除</a> ", new[] { x.FLogID, x.FName })
               :
               string.Format(@"<a  href='/User/EditUser?loginID={0}'>编辑</a> | <a href='#' onclick=""DeleteUser('{2}','{1}')"" style='color: Red'>删除</a> ", new[] { x.FLogID, x.FName, x.FLogID_En })).Named("操作").Encode(false);

       column.For(p => p.FLogID).Named("用户名");
       column.For(p => p.FName).Named("姓名");

   }).Empty("暂无记录")
    </div>
    <div class="clear">
        <span style="float: left; width: 583px">共 @Model.TotalItemCount 条记录，页 @Model.CurrentPageIndex/@Model.TotalPageCount</span></div>
    <div class="clear">
        @Html.Pager(Model, new PagerOptions { ContainerTagName = "span", PageIndexParameterName = "id", AlwaysShowFirstLastPageNumber = true, HorizontalAlign = "center", FirstPageText = "&lt;&lt;", LastPageText = "&gt;&gt;" }, new { style = "float:center;width:583px" })
    </div>
    @Html.Hidden("hdOrgNo", ViewData["orgNo"])
    @Html.Hidden("hdorgName", ViewData["orgName"])
    @Html.Hidden("parOrgNo", ViewData["parOrgNo"])
    @Html.Hidden("hdFEmp_Status", ViewData["FEmp_Status"])
</body>
</html>
